%% @doc templel_context のテスト
%%
-module(t_templel_context).
-import(templ, [init/1]).
-import(templel_context, [get_by_key/1,get_by_key/2,get_by_index/1,get_by_index/2]).

-include_lib("eunit/include/eunit.hrl").


get_by_key_test_() ->
	D = dict:from_list([{foo,bar},{a,[b,c]}]),
	[?_assertMatch(bar, get_by_key(D, foo)),
	 ?_assertMatch([b,c], get_by_key(D, {name,123,a})),
	 ?_assertError({novalue,hoge}, get_by_key(D, hoge)),
	 ?_assertError({badargs,_}, get_by_key([], foo))
	].

default_get_by_key_test_() ->
	init([{foo,bar},{a,[b,c]}]),
	[?_assertMatch(bar, get_by_key(foo)),
	 ?_assertMatch([b,c], get_by_key({name,123,a})),
	 ?_assertError({novalue,_}, get_by_key(hoge))
	].
	

get_by_index_test_() ->
	D = dict:from_list([{foo,bar},{a,[b,c,d]},{e,f}]),
	[?_assertMatch([b,c,d], get_by_index(D, 0)),
	 ?_assertMatch(bar, get_by_index(D, 2)),
	 ?_assertMatch(bar, get_by_index(D, {integer,1,2})),
	 ?_assertError(outofbounds, get_by_index(D, 100)),
	 ?_assertError(outofbounds, get_by_index(D, -1)),
	 ?_assertError(outofbounds, get_by_index([], foo))
	].

default_get_by_index_test_() ->
	init([{foo,bar},{a,[b,c,d]},{e,f}]),
	[?_assertMatch([b,c,d], get_by_index(0)),
	 ?_assertMatch(bar, get_by_index(2)),
	 ?_assertMatch(bar, get_by_index({integer,1,2})),
	 ?_assertError(outofbounds, get_by_index(100)),
	 ?_assertError(outofbounds, get_by_index(-1))
	].
